package com.xuxin.pda.base;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.blankj.utilcode.util.ConvertUtils;

/**
 * Created by xu_xin
 * Created on 2021/2/3 0003
 * 检测二维码
 */
public abstract class BasePDAActivity extends BaseActivity {

    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(BaseConstant.pda_broadcast);
        registerReceiver(broadcastReceiver, intentFilter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unregisterReceiver(broadcastReceiver);
    }

    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(BaseConstant.pda_broadcast)) {
                String pda_message = ConvertUtils.bytes2String(intent.getByteArrayExtra(BaseConstant.pda_name));
                onPDASuccess(pda_message);
            }
        }
    };

    public abstract void onPDASuccess(String message);
}